package com.joker.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充日期处理器
 *
 * @Author JokerKS
 * @Date 2021/12/25 17:54
 * @Version 1.0
 */
@Slf4j
@Component //注意：需要把处理器加入到IOC容器中
public class MyMetaObjectHandler implements MetaObjectHandler {

	//插入时填充策略
	@Override
	public void insertFill(MetaObject metaObject) {
		log.info("start insert fill...");
		this.setFieldValByName("createTime", new Date(), metaObject);
		this.setFieldValByName("updateTime", new Date(), metaObject);
	}

	//更新时填充策略
	@Override
	public void updateFill(MetaObject metaObject) {
		log.info("start update fill...");
		this.setFieldValByName("updateTime", new Date(), metaObject);
	}
}
